using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web;

namespace Active.Core
{
    /// <summary>
  /// Utilities for the entire solution to use.
  /// </summary>
    public static class Utils
    {
        #region Authorization Rules

        /// <summary>
        /// Gets a value indicating whether this instance is customer employee.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is customer employee; otherwise, <c>false</c>.
        /// </value>
        public static bool IsCustomerEmployee
        {
            get
            {
                return Csla.ApplicationContext.User.IsInRole(Resource.CustomerEmployeeRole);
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is customer manager.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is customer manager; otherwise, <c>false</c>.
        /// </value>
        public static bool IsCustomerManager
        {
            get
            {
                return Csla.ApplicationContext.User.IsInRole(Resource.CustomerManagerRole);
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is media employee.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is media employee; otherwise, <c>false</c>.
        /// </value>
        public static bool IsMediaEmployee
        {
            get
            {
                return Csla.ApplicationContext.User.IsInRole(Resource.MediaEmployeeRole);
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is media manager.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is media manager; otherwise, <c>false</c>.
        /// </value>
        public static bool IsMediaManager
        {
            get
            {
                return Csla.ApplicationContext.User.IsInRole(Resource.MediaManagerRole);
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is general manager.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is general manager; otherwise, <c>false</c>.
        /// </value>
        public static bool IsGeneralManager
        {
            get
            {
                return Csla.ApplicationContext.User.IsInRole(Resource.GeneralManagerRole);
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is finance employee.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is finance employee; otherwise, <c>false</c>.
        /// </value>
        public static bool IsFinanceEmployee
        {
            get
            {
                return Csla.ApplicationContext.User.IsInRole(Resource.FinanceEmployeeRole);
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is admin.
        /// </summary>
        /// <value><c>true</c> if this instance is admin; otherwise, <c>false</c>.</value>
        public static bool IsAdmin
        {
            get
            {
                return Csla.ApplicationContext.User.IsInRole(Resource.AdminRole);
            }
        }

        #endregion

        /// <summary>
        /// Gets the relative root of the website.
        /// </summary>
        /// <value>A string that ends with a '/'.</value>
        public static string RelativeWebRoot
        {
            get { return VirtualPathUtility.ToAbsolute("~/"); }
        }

        /// <summary>
        /// Determines whether the specified state text is working.
        /// </summary>
        /// <param name="stateText">The state text.</param>
        /// <returns>
        /// 	<c>true</c> if the specified state text is working; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsWorking(string stateText)
        {
            if (stateText != "End")
            {
                return Csla.ApplicationContext.User.IsInRole(stateText.Replace("Working", string.Empty));
            }
            return false;
        }
    }
}
